package com.coupons.business.partnerpage.dao;

import java.util.List;

import com.coupons.business.common.exception.BaseCouponsAppException;
import com.coupons.business.common.vo.Page;
import com.coupons.business.common.vo.decorator.PageRowMapper;
import com.coupons.business.util.BaseUtilDAO;

public class PartnerPageDAO extends BaseUtilDAO implements IPartnerPageDAO {

	public void createPage(Page objaPage) throws BaseCouponsAppException 
	{
		int pageId= getSequenceNextValue("page_sq");
		Object obj[] = new Object[] { 
				new Integer(pageId),
				objaPage.getPageName(),
				objaPage.getDescription()
				};
		
		int rtnVal = this.saveOrUpdateOrDelete(PAGE_INSERT_STATEMENT.toString(), obj);
		if(rtnVal <= 0) {
			//logger.error("Unable to insert record into PAGE table");
			System.out.println("Unable to insert record into PAGE table");
			return;
		}
	}

	public void updatePage(Page objaPage) throws BaseCouponsAppException 
	{
		Object obj[] = new Object[] { 
				objaPage.getPageName(),
				objaPage.getDescription(),
				new Integer(objaPage.getPageId())
				};		
		 this.saveOrUpdateOrDelete(PAGE_UPDATE_STATEMENT.toString(), obj);		
	}

	public Page getPage(int pageId) throws BaseCouponsAppException 
	{
		try {
			Object objParams[] = new Object[]{new Integer(pageId)};
			List list = this.findRecords(GET_PAGE_STATEMENT, objParams,new PageRowMapper());
			
			if (null!=list && list.size()>0){
				
					return (Page)list.get(0);
			}
			else
				return null;
		} catch (Exception e) {
			
			e.printStackTrace();
		}
		System.out.println("ok");
		return null;
		
	}
	
	public List<Page> getAllPages()throws BaseCouponsAppException 
	{		
		try {
			List list = this.findRecords(GET_ALL_PAGES_STATEMENT, new PageRowMapper());
			return list;
		} catch (Exception e) {
			
			e.printStackTrace();
		}		
		return null;
	}

}
